using System;
using GameStateManagement;
using Microsoft.Phone.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Life
{
    // Main panel for Help screen
    class HelpPanel : ScrollingPanelControl
    {
        public HelpPanel(ContentManager content, bool isColumn, float spacing, int screenWidth)
            : base(isColumn, spacing)
        {
            SpriteFont titleFont = content.Load<SpriteFont>("Font\\MenuTitle");
            SpriteFont headerFont = content.Load<SpriteFont>("Font\\MenuHeader");
            SpriteFont detailFont = content.Load<SpriteFont>("Font\\Description");

            AddChild(new TextControl("Help", titleFont));

            AddChild(new TextControl("Basics", headerFont, Color.DarkGreen));
            AddChild(new TextArea("Cells will grow and die based on their surroundings.  For each generation, a set of rules is applied to determine whether a cell lives or dies.", detailFont, Color.White, screenWidth));

            AddChild(new TextControl("Rules", headerFont, Color.DarkGreen));
            AddChild(new TextArea("1. A live cell with fewer than 2 live neighbors dies.", detailFont, Color.White, screenWidth));
            AddChild(new TextArea("2. A live cell with 2 or 3 live neighbors lives.", detailFont, Color.White, screenWidth));
            AddChild(new TextArea("3. A live cell with more than 3 live neighbors dies.", detailFont, Color.White, screenWidth));
            AddChild(new TextArea("4. A dead cell with 3 live neighbors lives.", detailFont, Color.White, screenWidth));

            AddChild(new TextControl("Deleting Saved Games", headerFont, Color.DarkGreen));
            AddChild(new TextArea("To delete a saved game, press and hold an existing saved game in the Save and Load screens.", detailFont, Color.White, screenWidth));

            // TODO: Move About to separate screen
            AddChild(new TextControl("About", titleFont, Color.White));

            AddChild(new TextArea("The Game of Life was invented by the British mathematician John Horton Conway in 1970.", detailFont, Color.White, screenWidth));
            TextArea conwayLink = new TextArea("http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life", detailFont, Color.Blue, screenWidth);
            conwayLink.Tapped += ExternalWebNavigate;
            AddChild(conwayLink);

            AddChild(new TextArea("This version was developed by Matt Lott.", detailFont, Color.White, screenWidth));
            TextArea authorLink = new TextArea("http://www.mattlott.com/GameOfLife.htm", detailFont, Color.Blue, screenWidth);
            authorLink.Tapped += ExternalWebNavigate;
            AddChild(authorLink);
            AddChild(new TextControl("Version 1.2", detailFont, Color.White));

            // Force layout (all controls will size themselves)
            Layout(0, 0);
        }

        private void ExternalWebNavigate(object sender, EventArgs args)
        {
            if (sender is TextArea)
            {
                TextArea ta = sender as TextArea;
                
                WebBrowserTask wbt = new WebBrowserTask();
                wbt.Uri = new Uri(ta.Text);
                wbt.Show();
            }
        }
    }
}
